package fr.oz.mobile.module.profile.day 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import fr.digitas.flowearth.conf.Conf;
	import fr.digitas.flowearth.text.styles.styleManager;
	import fr.oz.core.datas.ProfilListDatas;
	import fr.oz.mobile.common.ui.SelectButton;
	import fr.oz.mobile.module.IView;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class ProfilValidator extends Sprite implements IView
	{
		private var setButton:SelectButton;
		
		private var profil:ProfilListDatas;
		
		public function ProfilValidator(_profil:ProfilListDatas) 
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
			
			profil = _profil;
			
			setButton = new SelectButton();
			addChild(setButton);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			var tf:TextField = new TextField();
			styleManager.apply(tf, ".profile_input_name", profil.name);
			tf.type = TextFieldType.INPUT;
			
			var tf_btOK:TextField = new TextField();
			styleManager.apply(tf_btOK, ".profile_confirm_name", "OK");
			
			var bg:SetName = new SetName();
			bg.y = 370;
			bg.x = 22;
			addChild(bg);
			
			//styleManager.apply(bg.tf, ".profile_input_name", profil.name);
			
			//bg.tf.addEventListener(FocusEvent.FOCUS_IN, focusHandler);
			
			//var tf:TextField = new TextField();
			//tf.border = true;
			//tf.type = TextFieldType.INPUT;
			//addChild(tf);
			//tf.width = 400;
			
			tf.x = 22 + 15;
			tf.y = 370 + 10;
			tf_btOK.x = 22 + 380;
			tf_btOK.y = 370 + 12;
			addChild(tf_btOK);
			addChild(tf);
			
			bg.btOk.addEventListener(MouseEvent.CLICK, handleClick);
			
			tf_btOK.mouseEnabled = false;
			
			setButton.y = bg.y + bg.height + 20;
			setButton.x = (stage.stageWidth - setButton.width) >> 1;
			setButton.addEventListener(MouseEvent.CLICK, handleClick);
		}
		
		private function focusHandler(e:FocusEvent):void 
		{
			trace("FOCUS IN TEXFIELD");
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			trace("handleCLCIK SET BUTTON");
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		private function dispose(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
		}
		
		/* INTERFACE fr.oz.mobile.module.IView */
		
		public function getValue():ProfilListDatas
		{
			return profil;
		}
		
		public function removeView():void
		{
			
		}
		
		public function activeView():void
		{
			
		}
		
		public function get title():XMLList
		{
			return Conf.getDatas("wakeUpProfile").data.ui.profileName;
		}
		
		public function get cachePosY():int
		{
			return 220;
		}
		
	}

}